package com.pomty.pombook;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {
	public static final String TABLEPHOTO = "PHOTO";
	public static final String TABLEALBUM = "ALBUM";
	private static final String DATABASENAME = "pombook.db";
	private static final int DATABASEVERSION = 2;
	public static final String ALBUM_ID = "ID";
	public static final String ALBUM_NAME = "NAME";
	public static final String ALBUM_COVERID = "COVERID";
	public static final String ALBUM_COVER = "COVER";
	public static final String ALBUM_AID = "AID";
	public static final String PHOTO_ID = "ID";
	public static final String PHOTO_URL = "URL";
	public static final String PHOTO_URLBIG = "URLBIG";
	public static final String PHOTO_URLSMALL = "URLSMALL";
	public static final String PHOTO_LINK = "LINK";
	public static final String PHOTO_CAPTION = "CAPTION";
	public static final String PHOTO_AID = "AID";
	public static final String PHOTO_PID = "PID";
	public static final String CREATETABLEALBUM = "CREATE TABLE " + TABLEALBUM + "("
				+ ALBUM_ID + " INTEGER PRIMARY KEY, "
				+ ALBUM_NAME + " TEXT, "
				+ ALBUM_COVERID + " TEXT, "
				+ ALBUM_COVER + " TEXT, "
				+ ALBUM_AID + " TEXT"
				+ ");";
	
	private static final String CREATETABLEPHOTO = "CREATE TABLE " + TABLEPHOTO + "("
		+ PHOTO_ID + " INTEGER PRIMARY KEY, "
		+ PHOTO_URL + " TEXT, "
		+ PHOTO_URLBIG + " TEXT, "
		+ PHOTO_URLSMALL + " TEXT, "
		+ PHOTO_LINK + " TEXT, "
		+ PHOTO_CAPTION + " TEXT, "
		+ PHOTO_AID + " TEXT, "
		+ PHOTO_PID + " TEXT"
		+ ");";

	public DBHelper(Context context){
		super(context, DATABASENAME, null, DATABASEVERSION);
		
	}
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATETABLEALBUM);
		db.execSQL(CREATETABLEPHOTO);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		try
		{
			db.execSQL("DROP TABLE IF EXISTS PHOTO");
		
			db.execSQL("DROP TABLE IF EXISTS ALBUM");
		}
		catch (Exception e)
		{
			Log.e("drop table", e.getMessage());
		}
		onCreate(db);
	}

}
